<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <select name="" id="xuan">
        <option value="水果" id="fruit" > 水果</option>
        <option value="蔬菜" id="vc1"> 蔬菜</option>
    </select>
    <select name="" id="ca">
    
</select>
</body>

</html>
<script>
    var fruit = ['西瓜', '香蕉', '苹果', '葡萄', '榴莲', '水蜜桃', '芒果', '火龙果'];
    var vc = ['西红柿', '黄瓜', '土豆', '豆角', '蒜台'];
    var ca = document.querySelector('#ca');
    var xuan = document.querySelector("#xuan");
    xuan.onchange = function() {

        // ca.innerHTML = "";
        while (ca.childElementCount > 0) {
            ca.removeChild(ca.children[0]);
        }

        if (xuan.value == "水果") {
            for (var i = 0; i < fruit.length; i++) {
                var a = document.createElement('option');
                a.innerHTML = fruit[i];
                a.value = fruit[i];
                ca.appendChild(a);
            }
        }
        if (xuan.value == "蔬菜") {
            for (var i = 0; i < vc.length; i++) {
                var a = document.createElement('option');
                a.innerHTML = vc[i];
                a.value = vc[i];
                ca.appendChild(a);
            }
        }

    }
</script>